// stencil2word.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>

#include "Utils.h"
#include "FileNameUtils.h"

#include "ProgramOptions.h"

#include "Export.h"

#include <iostream>
using namespace std;

const wchar_t* cTryingToOpenFileMsg = L"Trying to open \"";
const wchar_t* cSkippingFileMsg = L"Skipping \""; 
const wchar_t* cSuccessful = L"Successful.";

const wchar_t* cTotalCountMsg = L"Total count: ";
const wchar_t* cErrorsCountMsg = L"Error count: ";
const wchar_t* cSkippedCountMsg = L"Skipped count: ";

int _tmain(int argc, _TCHAR* argv[])
{
	CProgramOptions Options;
	if( Options.ParseCommandLine(argc, argv) )
	{
		std::vector<tstring> InputFiles;
		Options.GetInputFileNames(InputFiles);

		if( InputFiles.size() == 0 )
			return 0 ;
		
		size_t ProcessedCount = 0;
		size_t ErrorsCount = 0;
		size_t SkippedCount = 0;

		std::wcout.imbue(std::locale(".OCP"));
		for(std::vector<tstring>::const_iterator It = InputFiles.begin();
			It != InputFiles.end();
			++It)
		{
			if( FileName2ImageType(*It) != imtUnknown )
			{
				std::wcout << cTryingToOpenFileMsg << *It << L"\"" << std::endl;
				if( !DoExport(*It, InputFiles.size() > 1, Options) )
					ErrorsCount++;
				else
				{
					std::wcout << cSuccessful << std::endl << std::endl;
					ProcessedCount++;
				}
			}
			else
			{
				std::wcout << cSkippingFileMsg << *It << L"\"" << std::endl << std::endl;
				SkippedCount++;
			}
		}

		std::wcout << cTotalCountMsg << InputFiles.size() << std::endl;
		std::wcout << cErrorsCountMsg << ErrorsCount << std::endl;
		std::wcerr << cSkippedCountMsg << SkippedCount << std::endl;
	}
	return 0;
}

